package com.doyens.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.BaseSaleAttr;
import com.doyens.gmall.model.product.SpuImage;
import com.doyens.gmall.model.product.SpuInfo;
import com.doyens.gmall.model.product.SpuSaleAttr;
import com.doyens.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuManageController {

    @Autowired
    private ManageService manageService;

    @GetMapping("/{page}/{limit}")
    public Result getSpuInfoPage(@PathVariable("page")Long page,
                                 @PathVariable("limit")Long limit,
                                 Long category3Id){
        Page<SpuInfo> spuInfoPage = new Page<SpuInfo>(page,limit);

        IPage<SpuInfo> iPage =manageService.getSpuInfoList(spuInfoPage,category3Id);
        return Result.ok(iPage);
    }

    //查询销售属性
    @GetMapping("baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> baseSaleAttrs = manageService.getBaseSaleAttrList();
        return Result.ok(baseSaleAttrs);
    }

    @PostMapping("saveSpuInfo")
    public Result saveSpuIo(@RequestBody SpuInfo spuInfo){
        manageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

    @GetMapping("/spuImageList/{spuId}")
    public Result getSpuImageList(@PathVariable("spuId")Long spuId){
        List<SpuImage> imageList = manageService.getSpuImageList(spuId);
        return Result.ok(imageList);
    }

    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result getSpuSalAttrList(@PathVariable("spuId")Long spuId){
        List<SpuSaleAttr> spuSaleAttrsList = manageService.getSpuSalAttrList(spuId);
        return Result.ok(spuSaleAttrsList);
    }


}
